<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>boost/python/call.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../function_invocation_and_creation.html" title="Chapter 4. Function Invocation and Creation">
<link rel="prev" href="../function_invocation_and_creation.html" title="Chapter 4. Function Invocation and Creation">
<link rel="next" href="boost_python_call_method_hpp.html" title="boost/python/call_method.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function_invocation_and_creation.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_call_method_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="function_invocation_and_creation.boost_python_call_hpp"></a><a class="link" href="boost_python_call_hpp.html" title="boost/python/call.hpp">boost/python/call.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call">Function
        <code class="computeroutput"><span class="identifier">call</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.introduction"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<pre class="programlisting"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">call</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="identifier">defines</span> <span class="identifier">the</span> <span class="identifier">call</span> <span class="identifier">family</span> <span class="identifier">of</span> <span class="identifier">overloaded</span> <span class="identifier">function</span> <span class="identifier">templates</span><span class="special">,</span> <span class="identifier">used</span> <span class="identifier">to</span> <span class="identifier">invoke</span> <span class="identifier">Python</span> <span class="identifier">callable</span> <span class="identifier">objects</span> <span class="identifier">from</span> <span class="identifier">C</span><span class="special">++.</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.function_call"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.function_call" title="Function call">Function
        <code class="computeroutput"><span class="identifier">call</span></code></a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">A2</span><span class="special">,</span> <span class="special">...</span> <span class="keyword">class</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">R</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">callable</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="identifier">A2</span> <span class="keyword">const</span><span class="special">&amp;,</span> <span class="special">...</span> <span class="identifier">An</span> <span class="keyword">const</span><span class="special">&amp;)</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                R is a pointer type, reference type, or a complete type with an accessible
                copy constructor
              </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                Invokes callable(a1, a2, ...an) in Python, where a1...an are the
                arguments to call(), converted to Python objects.
              </p></dd>
<dt><span class="term">Returns</span></dt>
<dd><p>
                The result of the Python call, converted to the C++ type R.
              </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                For a complete semantic description and rationale, see this page.
              </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function_invocation_and_creation.boost_python_call_hpp.example"></a><a class="link" href="boost_python_call_hpp.html#function_invocation_and_creation.boost_python_call_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
          The following C++ function applies a Python callable object to its two
          arguments and returns the result. If a Python exception is raised or the
          result can't be converted to a double, an exception is thrown.
        </p>
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">apply2</span><span class="special">(</span><span class="identifier">PyObject</span><span class="special">*</span> <span class="identifier">func</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">call</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;(</span><span class="identifier">func</span><span class="special">,</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">);</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function_invocation_and_creation.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_call_method_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>
